<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户管理</title>
</head>
<style type="text/css">
.tbyd{
    position: relative;
	left: 0px;
	top: 0px;
}
table tr th{
    width: 50px;
    height: 50px;
    font-size: 20px;
}
.tbyd .tenakd{
    width: 200px;
}
.xzcz{
    position: absolute;
	left: 500px;
	top: 50px;
}
.jtcz01{
    position: absolute;
	left: 600px;
	top: 50px;
}
.jtcz02{
    position: absolute;
	left: 680px;
	top: 50px;
}
.addyhyh{
    border: 1px solid gray;
    background-color: #F5F5F5;
    width: 500px;
	height: 150px;
	position: absolute;
	left: 500px;
	top: 100px;
	text-align: center;
}
.deleyhyh{
    border: 1px solid gray;
    background-color: #F5F5F5;
    width: 500px;
	height: 150px;
	position: absolute;
	left: 500px;
	top: 100px;
	text-align: center;
}
</style>
<body>
	<%!
	    private static final String JDBC_URL = "jdbc:mysql://localhost:3309/blog?useUnicode=true&characterEncoding=utf8";
	    private static final String DB_USER = "root";
	    private static final String DB_PWD = "ZLWL";
	    Map<String, String> hashMaps = new HashMap<String, String>();
	%>
	<%
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
			e.printStackTrace();
		}
		Connection conn;
		try {
			conn = DriverManager.getConnection(JDBC_URL, DB_USER, DB_PWD);
			Statement stmt = conn.createStatement();
			String sqlz = "select count(id) total from user_zc";
			ResultSet rsz = stmt.executeQuery(sqlz);
			int setnum = 0;
			while (rsz.next()) {
				int getnum = rsz.getInt(1);
				setnum = getnum;
			}
			String sqly = "select id from user_zc";
			ResultSet rsy = stmt.executeQuery(sqly);
			Map<String, String> hashMap1 = new HashMap<String, String>();
			int i = 1;
			while (rsy.next()) {
				hashMap1.put("id" + i, rsy.getString("id"));
				hashMaps.put("id" + i, rsy.getString("id"));
				System.out.println(hashMap1.get("id" + i));
				i++;
			}
			String sqlx = "select name from user_zc";
			ResultSet rsx = stmt.executeQuery(sqlx);
			Map<String, String> hashMap2 = new HashMap<String, String>();
			int j = 1;
			while (rsx.next()) {
				hashMap2.put("name" + j, rsx.getString("name"));
				System.out.println(hashMap2.get("name" + j));
				j++;
			}
			String sqlxy = "select password from user_zc";
			ResultSet rsxy = stmt.executeQuery(sqlxy);
			Map<String, String> hashMap3 = new HashMap<String, String>();
			int ij = 1;
			while (rsxy.next()) {
				hashMap3.put("password" + ij, rsxy.getString("password"));
				System.out.println(hashMap3.get("password" + ij));
				ij++;
			}
			response.getWriter().append("<table border='1' class='tbyd'>");
			response.getWriter().append("<tr>");
			response.getWriter().append("<th>ID</th>");
			response.getWriter().append("<th class='tenakd'>用户名</th>");
			response.getWriter().append("<th class='tenakd'>口令</th>");
			response.getWriter().append("</tr>");
			response.getWriter().append("</table>");
			int k = 1;
			while (k < (setnum + 1)) {
				response.getWriter().append("<table border='1' class='tbyd'>");
				response.getWriter().append("<tr>");
				response.getWriter().append("<th>");
				response.getWriter().append(hashMap1.get("id" + k));
				response.getWriter().append("</th>");
				response.getWriter().append("<th class='tenakd'>");
				response.getWriter().append(hashMap2.get("name" + k));
				response.getWriter().append("</th>");
				response.getWriter().append("<th class='tenakd'>");
				response.getWriter().append(hashMap3.get("password" + k));
				response.getWriter().append("</th>");
				response.getWriter().append("</tr>");
				response.getWriter().append("</table>");
				k++;
			}
			rsxy.close();
			rsx.close();
			rsy.close();
			rsz.close();
			stmt.close();
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	%>
	<button class="xzcz">选择操作</button>
	<button class="jtcz jtcz01 jtcz1">添加用户</button>
	<button class="jtcz jtcz02 jtcz2">删除用户</button>
	<div class="addyhyh">
	<br>
	<form action="/addyhyh" method="post">
    <span>输入新用户名:</span>
    <input type="text" name="newyhyhname" /><br><br>
    <span>输此用户口令:</span>
    <input type="text" name="newyhyhpassword" /><br><br>
    <button type="submit">提交</button>
    </form>
    </div>
    <div class="deleyhyh">
	<br><br><br>
	<form action="/deleteyhyh" method="post">
    <span>输入要删除的用户的ID:</span>
    <input type="text" name="deleteyhyhname" />
    <button type="submit">提交</button>
    </form>
    </div>
<script type='text/javascript' src='/static/js/jquery.min.js'></script>
<script type="text/javascript">
$(document).ready(function(){
	$(".jtcz").hide();
    $(".xzcz").click(function(){
    	$(".addyhyh").fadeOut();
    	$(".deleyhyh").fadeOut();
        $(".jtcz").slideToggle();
        })
});
$(document).ready(function(){
	$(".addyhyh").hide();
    $(".jtcz1").click(function(){
        $(".deleyhyh").fadeOut();
        $(".addyhyh").slideToggle();
        })
});
$(document).ready(function(){
	$(".deleyhyh").hide();
    $(".jtcz2").click(function(){
        $(".addyhyh").fadeOut();
        $(".deleyhyh").slideToggle();
        })
});
</script>
</body>
</html>